package com.cym.controller;

import com.cym.dto.ProductParam;
import com.cym.entity.Product;
import com.cym.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
@CrossOrigin //允许跨域访问
public class ProductController {
    @Autowired
    ProductService productService;

    //获取列表
    @RequestMapping("/getProductList")
    public List<Product> getProductList(@RequestBody ProductParam productParam){
        System.out.println("获取列表"+productParam);
        return productService.getProductList(productParam);
    }

    //添加
    @RequestMapping("/add")
    public String add(@RequestBody Product product){
        return productService.add(product);
    }

    //修改
    @RequestMapping("/update")
    public String update(@RequestBody Product product){
        return productService.update(product);
    }

    //删除
    @RequestMapping("/delete")
    public String delete(Integer productId){
        return productService.delete(productId);
    }
}
